home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / Portable Patmos / usr / include / g++ < prev    next >
Encoding:
Text File  |  1994-11-08  |  4.6 KB  |  160 lines  |  [TEXT/R*ch]

  1. // $Header: /b/source/CVS/src/usr.bin/lex/FlexLexer.h,v 1.3 1993/12/09 19:06:03 jtc Exp $
  2.  
  3. // FlexLexer.h -- define classes for lexical analyzers generated by flex
  4.  
  5. // Copyright (c) 1993 The Regents of the University of California.
  6. // All rights reserved.
  7. //
  8. // This code is derived from software contributed to Berkeley by
  9. // Kent Williams and Tom Epperly.
  10. //
  11. // Redistribution and use in source and binary forms are permitted provided
  12. // that: (1) source distributions retain this entire copyright notice and
  13. // comment, and (2) distributions including binaries display the following
  14. // acknowledgement:  ``This product includes software developed by the
  15. // University of California, Berkeley and its contributors'' in the
  16. // documentation or other materials provided with the distribution and in
  17. // all advertising materials mentioning features or use of this software.
  18. // Neither the name of the University nor the names of its contributors may
  19. // be used to endorse or promote products derived from this software without
  20. // specific prior written permission.
  21. // THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  22. // WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  23. // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  24.  
  25. #ifndef __FLEX_LEXER_H
  26. #define __FLEX_LEXER_H
  27.  
  28.  
  29. // This file defines two classes.  The first, FlexLexer, is an abstract
  30. // class which specifies the external interface provided to flex C++
  31. // lexer objects.  The second, yyFlexLexer, fills out most of the meat
  32. // of the lexer class; its internals may vary from lexer to lexer
  33. // depending on things like whether REJECT is used.
  34. //
  35. // If you want to create multiple lexer classes, you use the -P flag
  36. // to rename each yyFlexLexer to some other xxFlexLexer.
  37.  
  38. #include <iostream.h>
  39.  
  40. struct yy_buffer_state;
  41. typedef int yy_state_type;
  42.  
  43. class FlexLexer {
  44. public:
  45.     virtual ~FlexLexer()    { }
  46.  
  47.     const char* YYText()    { return yytext; }
  48.     int YYLeng()        { return yyleng; }
  49.  
  50.     virtual void
  51.         yy_switch_to_buffer( struct yy_buffer_state* new_buffer ) = 0;
  52.     virtual struct yy_buffer_state*
  53.         yy_create_buffer( istream* s, int size ) = 0;
  54.     virtual void yy_delete_buffer( struct yy_buffer_state* b ) = 0;
  55.     virtual void yyrestart( istream* s ) = 0;
  56.  
  57.     virtual int yylex() = 0;
  58.  
  59. protected:
  60.     char* yytext;
  61.     int yyleng;
  62. };
  63.  
  64.  
  65. class yyFlexLexer : public FlexLexer {
  66. public:
  67.     // arg_yyin and arg_yyout default to the cin and cout, but we
  68.     // only make that assignment when initializing in yylex().
  69.     yyFlexLexer( istream* arg_yyin = 0, ostream* arg_yyout = 0 )
  70.         {
  71.         yyin = arg_yyin;
  72.         yyout = arg_yyout;
  73.         yy_c_buf_p = 0;
  74.         yy_init = 1;
  75.         yy_start = 0;
  76.  
  77.         yy_did_buffer_switch_on_eof = 0;
  78.  
  79.         yy_looking_for_trail_begin = 0;
  80.         yy_more_flag = 0;
  81.         yy_more_len = 0;
  82.  
  83.         yy_current_buffer = 0;
  84.  
  85. #ifdef YY_USES_REJECT
  86.         yy_state_buf = new yy_state_type[YY_BUF_SIZE + 2];
  87. #else
  88.         yy_state_buf = 0;
  89. #endif
  90.         }
  91.  
  92.     virtual ~yyFlexLexer()
  93.         {
  94.         delete yy_state_buf;
  95.         }
  96.  
  97.     void yy_switch_to_buffer( struct yy_buffer_state* new_buffer );
  98.     struct yy_buffer_state* yy_create_buffer( istream* s, int size );
  99.     void yy_delete_buffer( struct yy_buffer_state* b );
  100.     void yyrestart( istream* s );
  101.  
  102.     virtual int yylex();
  103.  
  104. protected:
  105.     virtual int LexerInput( char* buf, int max_size );
  106.     virtual void LexerOutput( const char* buf, int size );
  107.     virtual void LexerError( const char* msg );
  108.  
  109.     void yyunput( int c, char* buf_ptr );
  110.     int yyinput();
  111.  
  112.     void yy_load_buffer_state();
  113.     void yy_init_buffer( struct yy_buffer_state* b, istream* s );
  114.  
  115.     yy_state_type yy_get_previous_state();
  116.     yy_state_type yy_try_NUL_trans( yy_state_type current_state );
  117.     int yy_get_next_buffer();
  118.  
  119.     istream* yyin;    // input source for default LexerInput
  120.     ostream* yyout;    // output sink for default LexerOutput
  121.  
  122.     struct yy_buffer_state* yy_current_buffer;
  123.  
  124.     // yy_hold_char holds the character lost when yytext is formed.
  125.     char yy_hold_char;
  126.  
  127.     // Number of characters read into yy_ch_buf.
  128.     int yy_n_chars;
  129.  
  130.     // Points to current character in buffer.
  131.     char* yy_c_buf_p;
  132.  
  133.     int yy_init;        // whether we need to initialize
  134.     int yy_start;        // start state number
  135.  
  136.     // Flag which is used to allow yywrap()'s to do buffer switches
  137.     // instead of setting up a fresh yyin.  A bit of a hack ...
  138.     int yy_did_buffer_switch_on_eof;
  139.  
  140.     // The following are not always needed, but may be depending
  141.     // on use of certain flex features (like REJECT or yymore()).
  142.  
  143.     yy_state_type yy_last_accepting_state;
  144.     char* yy_last_accepting_cpos;
  145.  
  146.     yy_state_type* yy_state_buf;
  147.     yy_state_type* yy_state_ptr;
  148.  
  149.     char* yy_full_match;
  150.     int* yy_full_state;
  151.     int yy_full_lp;
  152.  
  153.     int yy_lp;
  154.     int yy_looking_for_trail_begin;
  155.  
  156.     int yy_more_flag;
  157.     int yy_more_len;
  158. };
  159. #endif
  160.